<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>36 氪</title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <script type="text/javascript" src="static/js/jquery-1.7.2.min.js"></script>

    <style type="text/css">
        body {
            margin: 0px;
            padding: 0px;
        }
        .top-class{
            text-align: center;
            background-color: rgba(0, 153, 204, .9);
            height: 50px;
            line-height: 50px;
            vertical-align: middle;
            color: #ffffff;
            font-size: 24px;
        }
        .body-class {
            margin: 0px auto;
            width: 80%;
            height: 500px;
            line-height: 500px;
            vertical-align: middle;
            background-color: #FED25E;
            border-radius: 10px;
            border: 5px solid #ffffff;
        }
        .bottom-class{
            text-align: center;
            margin: 0px auto;
            width: 80%;
            height: 100px;
            background-color: #845404;
            border-radius: 5px;
            border: 5px solid #ffffff;
            color: white;
            font-size: 64px;
        }
        .body-class img{border: 2px solid yellow;}
    </style>
</head>
<body>

<div>
    <div class="top-class">22222</div>
</div>
<div style="padding-top: 40px;">
    <div class="body-class" align="center">
        <img id="caichengyuid" src="http://localhost:8080/static/img/%E4%B8%80%E5%88%80%E4%B8%A4%E6%96%AD.png">
    </div>
</div>
<div style="padding-top: 50px;">
    <div class="bottom-class" id="right_answers">无时无刻</div>
</div>

<script type="text/javascript">
    $(document).ready(function () {
        initDsGamesDay();
    });
    function initDsGamesDay() {
        var websocket = null;
        //判断当前浏览器是否支持WebSocket
        if ('WebSocket' in window) {
            websocket = new WebSocket("ws://localhost:20008/initDsGamesDataDayServer");
        } else {
            alert('Not support websocket')
        }
        //连接发生错误的回调方法
        websocket.onerror = function () {
            setMessageInnerHTML("error");
        };
        //连接成功建立的回调方法
        websocket.onopen = function (event) {
            setMessageInnerHTML("open");
        }
        websocket.onmessage = function (event) {

            var reslut = eval("(" + event.data + ")");
            console.log(JSON.stringify(reslut) + '-reslut---' + reslut)
            console.log('---------------------------------')

            $('#caichengyuid').attr('src', reslut.url);
            $('#right_answers').html("").append(reslut.right_answers);
        }
        //连接关闭的回调方法
        websocket.onclose = function () {
            setMessageInnerHTML("close");
        }
        //监听窗口关闭事件，当窗口关闭时，主动去关闭websocket连接，防止连接还没断开就关闭窗口，server端会抛异常。
        window.onbeforeunload = function () {
            websocket.close();
        }

        //将消息显示在网页上
        function setMessageInnerHTML(innerHTML) {
            $('errorid').append(innerHTML);
        }

        //关闭连接
        function closeWebSocket() {
            websocket.close();
        }

        //发送消息
        function send() {
            var message = document.getElementById('text').value;
            websocket.send(message);
        }
    }




</script>
</body>
</html>
